<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<script>
var obj = {"name":"linxinfa", "blog":"https://blog.csdn.net/linxinfa"};
// 将字典对象转为json字符串
var json_str = JSON.stringify(obj);
document.write("json str: " + json_str);

// 格式化json字符串
document.write( "<br>" );
document.write( "<br>" );
document.write( "格式化json字符串:" );
var json_str2 = JSON.stringify(obj, null, 4) //使用四个空格缩进
document.write("<pre>" + json_str2 + "</pre>" );

// 将json字符串转为为字典对象
var json_obj = JSON.parse(json_str2);
document.write("my blog: " + json_obj.blog);
</script>